//新增弹出新增浮层
$('.crime-search-btn').click(function() {
    $('.crime-msk').fadeIn(400);
})
$('.crime-msk-close').click(function() {
    $('.crime-msk').fadeOut(400);
})
$('.crime-msk-cancel').click(function() {
    $('.crime-msk').fadeOut(400);
})

//证件判断
$('.card-num input').blur(function() {
    var cardNumVal = $('.card-num input').val();
    // 身份证
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    // 普通护照
    var reg1 = /^[a-zA-Z]{5,17}$/;
    var reg2 = /^[a-zA-Z0-9]{5,17}$/;
    // 港澳通行证
    var reg3 = /^[HMhm]{1}([0-9]{10}|[0-9]{8})$/;
    // 台湾通行证
    var reg4 = /^[0-9]{8}$/;
    var reg5 = /^[0-9]{10}$/;

    if($('.card-check select').val() === "1") {
         if(reg.test(cardNumVal) === false) {
            $(this).attr('class','error');
            layer.msg('身份证不合法！', {
                time: 1000
            });
         }else{
            $(this).removeAttr('class');
            //通过身份证获取生日、性别、年龄
            var birthday;
            var year;
            var month;
            var day;
            var sex;
            var age;
            if(cardNumVal.length==15){
            	year = "19" + cardNumVal.substring(6,8);
            	month = cardNumVal.substring(8,10);
            	//month = cardNumVal.substring(8,10)<10?("0"+cardNumVal.substring(6,8)+1):cardNumVal.substring(6,8)+1;
            	day = cardNumVal.substring(10,12);
            	sex = cardNumVal.substring(14,15)%2==0?2:1;
            }else if(cardNumVal.length==18){
            	year = cardNumVal.substring(6,10);
            	month = cardNumVal.substring(10,12);
            	day = cardNumVal.substring(12,14);
            	sex = cardNumVal.substring(14,17)%2==0?2:1;
            }
            birthday = year +"-"+month+"-"+day;  
            var birthDate = new Date(year+"/"+month+"/"+day);
            var nowDateTime = new Date();
            age = nowDateTime.getFullYear() - birthDate.getFullYear();
            //再考虑月、天的因素;.getMonth()获取的是从0开始的，这里进行比较，不需要加1
            if (nowDateTime.getMonth() < birthDate.getMonth() || (nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())) {
                age--;
            }
            console.log(birthday);
            console.log(sex);
            console.log(age);
            $("[name='wxUser.birthday']").val(birthday);
			//给性别赋值
			$("[name='wxUser.sex']").val(sex);
            $("[name='wxUser.age']").val(age);
         }
    }
    if($('.card-check select').val() === 4) {
        if(reg1.test(cardNumVal) === false || reg2.test(cardNumVal) === false) {
            $(this).attr('class','error');
            layer.msg('护照不合法！', {
                time: 1000
            });
        }else{
            $(this).removeAttr('class');
        }
    }
    if($('.card-check select').val() === 5) {
        if(reg3.test(cardNumVal) === false) {
            $(this).attr('class','error');
            layer.msg('港澳通行证不合法！', {
                time: 1000
            });
        }else{
            $(this).removeAttr('class');
        }
    }
    if($('.card-check select').val() === 6) {
        if(reg4.test(cardNumVal) === false || reg5.test(cardNumVal) === false) {
            $(this).attr('class','error');
            layer.msg('台湾通行证不合法！', {
                time: 1000
            });
        }else{
            $(this).removeAttr('class');
        }
    }
})